package cn.stronglink.asset.module.sys.role.service;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.toolkit.IdWorker;

import cn.stronglink.asset.model.Role;
import cn.stronglink.asset.model.User;
import cn.stronglink.asset.module.sys.role.mapper.RoleMapper;
import cn.stronglink.suite.core.util.WebUtil;

@Service
@Transactional(rollbackFor=Exception.class) 
public class RoleService {
	
	@Autowired
	private RoleMapper roleMapper;

	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public List<Role> qryRoles(Map<String, Object> params) {
		return roleMapper.qryRoles(params);
	}
	
	public void insertRoles(User user){
		roleMapper.insertRoles(user);
	}

	public void updateRoleById(Role role) {
		role.setUpdateTime(new Date());
		role.setUpdateBy(WebUtil.getCurrentUser());
		roleMapper.updateRoleById(role);		
	}

	public void delRole(Long id) {
		roleMapper.delRole(id);		
	}
	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public Integer getRoleUsers(Long id) {
		return roleMapper.getRoleUsers(id);
	}
	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public int getRoleByName(String name) {
		return roleMapper.getRoleByName(name);
	}

	public void insertRole(Role role) {
		role.setId(IdWorker.getId());
		role.setCreateTime(new Date());
		role.setCreateBy(WebUtil.getCurrentUser());
		roleMapper.insertRole(role);
		
	}
	
	

}
